Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
jsrsasign
Advanced tools
opensource free pure JavaScript cryptographic library supports RSA/RSAPSS/ECDSA/DSA signing/validation, ASN.1, PKCS#1/5/8 private/public key, X.509 certificate, CRL, OCSP, CMS SignedData, TimeStamp and CAdES and JSON Web Signature(JWS)/Token(JWT)/Key(JWK)
The jsrsasign npm package is a comprehensive library for cryptographic operations, including RSA/DSA/ECDSA key generation, digital signatures, X.509 certificate handling, and more. It is widely used for implementing security features in JavaScript applications.
RSA Key Generation
This feature allows you to generate RSA key pairs. The code sample demonstrates generating a 2048-bit RSA key pair using the KEYUTIL.generateKeypair method.
const rsaKeypair = KEYUTIL.generateKeypair('RSA', 2048);
console.log(rsaKeypair);
Digital Signature
This feature allows you to create digital signatures. The code sample shows how to sign a message using an RSA private key and the SHA256withRSA algorithm.
const rsa = new RSAKey();
rsa.readPrivateKeyFromPEMString('-----BEGIN PRIVATE KEY-----...');
const sig = new KJUR.crypto.Signature({alg: 'SHA256withRSA'});
sig.init(rsa);
sig.updateString('message');
const signature = sig.sign();
console.log(signature);
X.509 Certificate Handling
This feature allows you to handle X.509 certificates. The code sample demonstrates reading a PEM-encoded certificate and extracting the subject string.
const pemCert = '-----BEGIN CERTIFICATE-----...';
const x509 = new X509();
x509.readCertPEM(pemCert);
console.log(x509.getSubjectString());
JWT (JSON Web Token) Handling
This feature allows you to create and verify JSON Web Tokens (JWT). The code sample shows how to sign a JWT using the HS256 algorithm and a secret key.
const header = {alg: 'HS256', typ: 'JWT'};
const payload = {sub: '1234567890', name: 'John Doe', iat: 1516239022};
const sHeader = JSON.stringify(header);
const sPayload = JSON.stringify(payload);
const sJWT = KJUR.jws.JWS.sign('HS256', sHeader, sPayload, 'secret');
console.log(sJWT);
The 'crypto' module is a built-in Node.js module that provides cryptographic functionality, including a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions. It is more low-level compared to jsrsasign and is typically used for server-side cryptographic operations.
The 'jsonwebtoken' package is a popular library for creating and verifying JSON Web Tokens (JWT). It is more specialized than jsrsasign, focusing specifically on JWT handling, and is widely used in authentication and authorization scenarios.
The 'node-forge' package is a comprehensive library for implementing various cryptographic operations in JavaScript. It provides functionalities for key generation, digital signatures, encryption/decryption, and more. It is similar to jsrsasign in terms of the breadth of cryptographic features it offers.
The 'jsrsasign' (RSA-Sign JavaScript Library) is an opensource free pure JavaScript cryptographic library supports RSA/RSAPSS/ECDSA/DSA signing/validation, ASN.1, PKCS#1/5/8 private/public key, X.509 certificate, CRL, CMS SignedData, TimeStamp and CAdES and JSON Web Signature(JWS)/Token(JWT)/Key(JWK).
Public page is https://kjur.github.io/jsrsasign .
github TOP|API doc|Wiki|Node sample
> npm install jsrsasign jsrsasign-util
> bower install jsrsasign
> <script src="https://cdnjs.cloudflare.com/ajax/libs/jsrsasign/8.0.20/jsrsasign-all-min.js"></script>
Loading encrypted PKCS#5 private key:
> var rs = require('jsrsasign');
> var rsu = require('jsrsasign-util');
> var pem = rsu.readFile('z1.prv.p5e.pem');
> var prvKey = rs.KEYUTIL.getKey(pem, 'passwd');
Sign string 'aaa' with the loaded private key:
> var sig = new a.Signature({alg: 'SHA1withRSA'});
> sig.init(prvKey);
> sig.updateString('aaa');
> var sigVal = sig.sign();
> sigVal
'd764dcacb...'
published | fixed version | title/advisory | CVE | CVSS |
---|---|---|---|---|
2020Jun22 | 8.0.19 | ECDSA signature validation vulnerability by accepting wrong ASN.1 encoding | CVE-2020-14966 | 5.5 |
2020Jun22 | 8.0.18 | RSA RSAES-PKCS1-v1_5 and RSA-OAEP decryption vulnerability with prepending zeros | CVE-2020-14967 | 4.8 |
2020Jun22 | 8.0.17 | RSA-PSS signature validation vulnerability by prepending zeros | CVE-2020-14968 | 4.2 |
Here is full published security advisory list.
If you like jsrsasign and my other project, you can support their development by donation through any of the platform/services below. Thank you as always.
You can sponsor jsrsasign with the GitHub Sponsors program.
You can donate cryptocurrency to jsrsasign using the following addresses:
FAQs
opensource free pure JavaScript cryptographic library supports RSA/RSAPSS/ECDSA/DSA signing/validation, ASN.1, PKCS#1/5/8 private/public key, X.509 certificate, CRL, OCSP, CMS SignedData, TimeStamp and CAdES and JSON Web Signature(JWS)/Token(JWT)/Key(JWK)
The npm package jsrsasign receives a total of 411,625 weekly downloads. As such, jsrsasign popularity was classified as popular.
We found that jsrsasign demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.